<template xmlns="http://www.w3.org/1999/html">
    <SMycourseLayout>
      <div class="content-container">
        <h2 class="welcome-text">同学，您好。欢迎使用AIGC智育优学教育平台。</h2>
        <div class="schedule-table">
          <table>
            <colgroup>
              <col />
              <col />
              <col />
              <col />
              <col />
              <col />
              <col />
              <col />
              <col />
            </colgroup>
            <thead>
            <tr>
              <th></th>
              <th></th>
              <th>星期一</th>
              <th>星期二</th>
              <th>星期三</th>
              <th>星期四</th>
              <th>星期五</th>
              <th>星期六</th>
              <th>星期日</th>
            </tr>
            </thead>
            <tbody>
            <!-- 遍历每天的 5 节课 -->
            <tr v-for="period in 5" :key="period">
              <td v-if="period === 1" class="time-label" rowspan="5">全天</td>
              <td class="period">第 {{ period }} 节</td>
              <td v-for="day in ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']" :key="day">
                <template v-for="course in courses" :key="course.courseManageId" v-if="courses.length>0">
                  <div
                      v-if="course.day === day && course.period === period"
                      class="course-cell"
                      @click="goToLessonSchedule(course.courseManageId)"
                  >
                    <div class="course-name">{{ course.courseName }}</div>
                    <div class="classroom">{{ course.classroomName }}</div>
                    <div class="classroom">{{ course.userName }}</div>
                  </div>
                </template>
              </td>
            </tr>
            </tbody>
          </table>
        </div>
      </div>
    </SMycourseLayout>
</template>

<script lang="ts" setup>
import {onMounted, ref} from 'vue';
import {useRouter} from 'vue-router';
import SMycourseLayout from '@/components/SMycourseLayout.vue';
import {courseManagelistService} from '@/api/studentcourse.js';
import {useCounterStore} from '@/stores/counter'
import {useCourseManageIdStore} from '@/stores/courseManageId'

const router = useRouter();
let store=useCounterStore()
const courseManageIdStore = useCourseManageIdStore();
// 定义课程数据222
const courses = ref([
  {
    courseManageId: null,
    courseName: '',
    userId: null,
    period: null,
    classroomName: '',
    userName: '',
    day: ''
  }
  // 可以添加更多课程
]);

const courseManageList = async () => {
  courses.value = (await courseManagelistService()).data
  console.log(123)
  console.log(courses.value)
};
courseManageList();

// 添加跳转方法
const goToLessonSchedule = (courseManageId) => {
  try {
    store.courseManageId=courseManageId;
    courseManageIdStore.setCourseManageId(courseManageId);
    const courseManageId1=courseManageIdStore.courseManageId;
    console.log('学生端的courseManageId1',courseManageId1)
    router.push({
      name:'student_chat',
      params:{courseManageId:courseManageId}
      });
  } catch (error) {
    console.error('导航错误：', error);
   }
};
</script>

<style scoped>
.content-container {
  padding: 0 20px;
  height: 100%;
  width: 100%;
}

.welcome-text {
  margin: 0 0 20px;
  padding-top: 5px;
  color: #333;
  font-size: 1.2em;
}

.schedule-table {
  width: 100%;
  padding: 20px 0;
  min-width: 800px;
}

table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #ddd;
  table-layout: fixed;
  min-width: 800px;
}

table colgroup col:nth-child(1) { width: 25px; }
table colgroup col:nth-child(2) { width: 25px; }
table colgroup col:nth-child(n+3) { width: calc((100% - 50px) / 7); }

th, td {
  border: 1px solid #ddd;
  text-align: center;
  position: relative;
  padding: 0;
  height: 100px;
  box-sizing: border-box;
  overflow: hidden;
}

td:not(.time-label):not(.period) {
  position: relative;
}

td:not(.time-label):not(.period) > * {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  text-align: center;
}

tr:not(:first-child) {
  height: 100px;
}

th {
  height: 30px;
  background-color: #f5f7fa;
  color: #606266;
  font-weight: normal;
  vertical-align: middle;
}

.time-label, .period {
  background-color: #f5f7fa;
  font-weight: bold;
  writing-mode: vertical-lr;
  text-orientation: upright;
  width: 25px !important;
  min-width: 25px !important;
  max-width: 25px !important;
  overflow: hidden;
  white-space: nowrap;
  height: 100px;
}

.course-cell {
  background-color: #e6f3ff;
  color: #409EFF;
  font-weight: 500;
  transition: all 0.3s;
  cursor: pointer;
  user-select: none; /* 防止文字被选中 */
  flex-direction: column; /* 垂直排列 */
}

.course-cell:hover {
  background-color: #d0e7ff;
  transform: scale(1.02); /* 添加轻微的放大效果 */
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); /* 添加悬浮阴影 */
}

.course-cell:active {
  transform: scale(0.98); /* 点击时的按压效果 */
}

td > div, th > div {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

td:not(.time-label):not(.period):hover {
  background-color: #f0f9ff;
  cursor: pointer;
}

td > * {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 5px;
}

@media screen and (max-width: 800px) {
  .schedule-table {
    overflow-x: auto;
  }
}
</style>
